import { api } from './request';

// 用户查询请求参数
export interface UserQueryParams {
  page?: number;
  size?: number;
  nickname?: string;
  college?: string;
  status?: number;
  role?: number;
  startDate?: string;
  endDate?: string;
}

// 用户信息
export interface UserInfo {
  userId: number;
  nickname: string;
  avatarUrl?: string;
  gender?: number;
  college?: string;
  grade?: string;
  creditPoints: number;
  role: number;
  status: number;
  createdAt: string;
  updatedAt: string;
}

// 分页响应
export interface PageResponse<T> {
  content: T[];
  totalElements: number;
  totalPages: number;
  size: number;
  number: number;
  first: boolean;
  last: boolean;
  empty: boolean;
}

// 用户更新请求
export interface UserUpdateRequest {
  nickname?: string;
  college?: string;
  grade?: string;
  role?: number;
}

// 用户批量操作请求
export interface UserBatchRequest {
  userIds: number[];
  action: 'enable' | 'disable' | 'delete';
}

// 用户管理API
export const userApi = {
  // 获取用户列表（分页查询）
  getUsers(params: UserQueryParams): Promise<PageResponse<UserInfo>> {
    return api.get('/api/admin/users', params);
  },

  // 获取用户详情
  getUserDetail(userId: number): Promise<UserInfo> {
    return api.get(`/api/admin/users/${userId}`);
  },

  // 更新用户信息
  updateUser(userId: number, data: UserUpdateRequest): Promise<UserInfo> {
    return api.put(`/api/admin/users/${userId}`, data);
  },

  // 启用用户
  enableUser(userId: number): Promise<void> {
    return api.put(`/api/admin/users/${userId}/enable`);
  },

  // 禁用用户
  disableUser(userId: number): Promise<void> {
    return api.put(`/api/admin/users/${userId}/disable`);
  },

  // 删除用户
  deleteUser(userId: number): Promise<void> {
    return api.delete(`/api/admin/users/${userId}`);
  },

  // 批量操作用户
  batchOperateUsers(data: UserBatchRequest): Promise<void> {
    return api.post('/api/admin/users/batch', data);
  },

  // 获取用户统计信息
  getUserStats(): Promise<{
    totalUsers: number;
    activeUsers: number;
    newUsersToday: number;
    disabledUsers: number;
  }> {
    return api.get('/api/admin/users/stats');
  },
};

export default userApi;